package com.huawei.su;


import java.util.Stack;

public class BM13 {
    public static void main(String[] args) {
        ListNode head = new ListNode(-1);
        ListNode next = new ListNode(1);
        head.next = next;
        isPail(head);
    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param head ListNode类 the head
     * @return bool布尔型
     */
    public static boolean isPail (ListNode head) {
        // write code here
        Stack<Integer> stack = new Stack<>();
        ListNode index = head;
        while(true){
            if(index == null){
                break;
            }
            stack.push(index.val);
            index = index.next;
        }

        index = head;
        while(true){
            if(index == null){
                break;
            }
            if(index.val != stack.pop()){
                return false;
            }
            index = index.next;
        }
        return true;
    }
}
